//
//  THJRevisePswVC.m
//  THJXHW
//
//  Created by 河南德艺 on 17/4/15.
//  Copyright © 2017年 河南德艺. All rights reserved.
//

#import "THJRevisePswVC.h"

@interface THJRevisePswVC ()

@end

@implementation THJRevisePswVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"修改密码";
    [self setUpNav];
    self.pswdTf1.secureTextEntry = YES;
    self.pswdTf2.secureTextEntry = YES;
    self.currentPswdTf.secureTextEntry = YES;
  
}
- (IBAction)submitBtnAction:(id)sender {
    
    if (self.currentPswdTf.text.length==0) {
        [self HUDShowMsg:@"输入当前密码" AfterDelayDimiss:1];
        return;
    }else if (self.pswdTf1.text.length==0){
        [self HUDShowMsg:@"输入新密码" AfterDelayDimiss:1];
        return;
    }else if (self.pswdTf2.text.length==0){
        [self HUDShowMsg:@"再次输入新密码" AfterDelayDimiss:1];
        return;
    }else if (![self.pswdTf1.text isEqual:self.pswdTf2.text]){
         [self HUDShowMsg:@"两次输入密码不一致" AfterDelayDimiss:1];
        return;
    }else if (self.pswdTf1.text.length>15||self.pswdTf1.text.length<6){
        [self HUDShowMsg:@"密码必须是6-15位" AfterDelayDimiss:1];
        return;
    }
    NSString * urlstr = [NSString stringWithFormat:@"%@%@",THJUrlDomain,@"index.php?f=member&r=member&m=edit_pwd"];
    NSString * token = [THJTools getToken];
    NSDictionary * dic = @{
                           @"oldpwd":self.currentPswdTf.text,
                           @"password":self.pswdTf1.text,
                           @"repassword":self.pswdTf2.text
                           };
    __weak typeof(self) weakself = self;
    [THJNetWork postDataFromUrl:urlstr parameters:dic Token:token callback:^(NSDictionary*receiveData, NSError *error) {
        NSLog(@"修改密码--%@",receiveData);
          [weakself HUDShowMsg:receiveData[@"tip"] AfterDelayDimiss:1];
            if([receiveData[@"status"] isEqual:@"200"]){
                [[NSUserDefaults standardUserDefaults] setObject:weakself.pswdTf1.text forKey:@"password"];
                [weakself performSelector:@selector(popToLastPage) withObject:nil afterDelay:1];
            }
        
    }];
}
-(void)popToLastPage{
    [self pop];
}
- (IBAction)dismissSelf:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}


@end



